package base_Suanfa.erchashu;

import java.util.Arrays;

public class FloydAlgothrim {
    public static void main(String[] args) {
        int min=32767;
        char vertex[]={ 'A','B','C','D','E','F','G'};
        int matrix[][]={{0,7,min,5,min,min,min},{7,0,8,9,7,min,min},{min,8,0,min,5,min,min},{5,9,min,0,15,6,min},{min,7,5,15,0,8,9},{min,min,min,6,8,0,11},{min,min,min,min,9,11,0}};
        Graph3 graph3=new Graph3(vertex,matrix);

        FloydDemo floydDemo=new FloydDemo();
        floydDemo.folyd(matrix);
        System.out.println("最短路径结果为");
        graph3.showGraph(graph3);
    }
}
class FloydDemo{
    public void folyd(int matrix[][]){
         for(int k=0;k<matrix.length;k++){
             for(int i=0;i<matrix.length;i++){
                 for(int j=0;j<matrix.length;j++){
                     int temp=matrix[i][k]+matrix[k][j];
                     if(matrix[i][j]>temp)
                         matrix[i][j]=temp;
                 }
             }
         }
    }
}
class Graph3{
    private char vertexs[];  //存放顶点
    private  int matrix[][];  //邻接矩阵

    public Graph3(char[] vertexs, int[][] matrix) {
        this.vertexs = vertexs;
        this.matrix = matrix;
    }
    public void showGraph(Graph3 graph) {
        for (int edge[] : graph.matrix) {
            System.out.println(Arrays.toString(edge));
        }
    }
}